/**************************************************************************************************
 *                                                                          
 * Copyright (c) 2004 - 2007 Winbond Electronics Corp. All rights reserved.      
 *                                                                         
 * FILENAME
 *     AC97.h
 *
 * VERSION
 *     1.0
 *
 * DESCRIPTION
 *     This file contains the register map of AC97 audio codec
 *
 * HISTORY
 *     02/09/2004		 Ver 1.0 Created by PC30 YCHuang
 *
 * REMARK
 *     None
 *     
 *************************************************************************************************/

#ifndef _NUC900_AUDIO_H_
#define _NUC900_AUDIO_H_

typedef INT (AU_CB_FUNC_T)(UINT8 *, UINT32);

// -----------------------------------------------------------------------------
//
//  @doc    WPDD_EXT
//
//  @enum   WAPI_INOUT | Direction of the Wave API function. Designates 
//          if the function is for input or output.
//
//  @flag   WAPI_IN |  Function or data is for input.
//
//  @flag   WAPI_OUT | Function or data is for output.
//
// -----------------------------------------------------------------------------
typedef enum {
    WAPI_IN = 0, 
    WAPI_OUT
} WAPI_INOUT, *PWAPI_INOUT;

typedef struct
{
    UINT32        sChannels;          // number of channels (i.e. mono, stereo...)
    UINT32        nSamplesPerSec;     // sample rate
    //PUINT32       pDMABufPTR;    // for H/W DMA , it must be 32 bytes alignment
    //UINT32        nDMALen;       // for H/W DMA , it must be 32 bytes alignment
    AU_CB_FUNC_T 	*fnWAVCallBack;
#ifdef ECOS
	cyg_handle_t	int_handle_audio;
	cyg_interrupt	int_holder_audio;
#endif	
    
} WAVEFORMATEX, *PWAVEFORMATEX, *LPWAVEFORMATEX;
typedef struct {
	UINT8 sample;              // Unsigned 8-bit sample
} SAMPLE_8_MONO;

typedef struct {
	INT16 sample;              // Signed 16-bit sample
} SAMPLE_16_MONO;

typedef struct {
	UINT8 sample_left;         // Unsigned 8-bit sample
	UINT8 sample_right;        // Unsigned 8-bit sample
} SAMPLE_8_STEREO;

typedef struct {
	INT16 sample_left;         // Signed 16-bit sample
	INT16 sample_right;        // Signed 16-bit sample
} SAMPLE_16_STEREO;
typedef union {
	SAMPLE_8_MONO m8;
	SAMPLE_16_MONO m16;
	SAMPLE_8_STEREO s8;
	SAMPLE_16_STEREO s16;
} PCM_SAMPLE, *PPCM_SAMPLE;

#define WPDM_CLOSE          1
//#define WPDM_CONTINUE       2
//#define WPDM_ENDOFDATA      3
//#define WPDM_GETDEVCAPS     4
#define WPDM_GETVOLUME      5
#define WPDM_OPEN           6
//#define WPDM_PAUSE          7
//#define WPDM_RESTART        8
#define WPDM_SETPLAYVOLUME   9
#define WPDM_SETRECVOLUME   10
#define WPDM_START          11
#define WPDM_STOP           12

#define AU_SAMPLE_RATE_48000	48000
#define AU_SAMPLE_RATE_44100	44100
#define AU_SAMPLE_RATE_32000	32000
#define AU_SAMPLE_RATE_24000	24000
#define AU_SAMPLE_RATE_22050	22050
#define AU_SAMPLE_RATE_16000	16000
#define	AU_SAMPLE_RATE_12000	12000
#define AU_SAMPLE_RATE_11025	11025
#define AU_SAMPLE_RATE_8000		8000

#define AU_CH_MONO		1
#define AU_CH_STEREO	2

#define MSB_FORMAT	1
#define IIS_FORMAT  2

#define AUOUT_DMA_LEN 4096
#define AUIN_DMA_LEN 4096

#define ADO_ERR_ID		0xFFFF0200	        /* Audio library ID */

/* Error Code */
#define ERR_AU_GENERAL_ERROR	        (ADO_ERR_ID | 0x04)
#define ERR_AU_INITDEV_FAIL		        (ADO_ERR_ID | 0x05)		/* initialize device error */
#define ERR_AU_ILL_BUFF_SIZE	        (ADO_ERR_ID | 0x06)		/* illegal callback buffer size */
#define ERR_AU_DMA_ALLOC                  (ADO_ERR_ID | 0x07)	/* audio DMA buffer alloc failed */
#define ERR_AC97_CODEC_RESET	        (ADO_ERR_ID | 0x08)		/* AC97 codec reset failed */
#define ERR_DEV_ACTIVE	                (ADO_ERR_ID | 0x09)		/* Device has been activated */
#define ERR_DEV_NOT_ACTIVE              (ADO_ERR_ID | 0x0A)     /* Device has not been activated */
#define ERR_NO_DEVICE			        (ADO_ERR_ID | 0x0B)	    /* audio device not available */
#define ERR_IOCTL_UNSUPPORT_CODE    	(ADO_ERR_ID | 0x0C)	    /* Unsupported IO control code */
#define ERR_IOCTL_UNKNOWN    	        (ADO_ERR_ID | 0x0D)     /* Would never occur */
#define ERR_NULL_WAVOUTCALLBACK     (ADO_ERR_ID | 0x0E)
#define ERR_NULL_WAVINCALLBACK     (ADO_ERR_ID | 0x0F)

typedef enum au_dev_e
{
	AU_DEV_AC97,
	AU_DEV_I2S,
	AU_DEV_ADC,
	AU_DEV_DAC,
	AU_DEV_MA3,
	AU_DEV_MA5,
	AU_DEV_W5691,
	AU_DEV_WM8753,
	AU_DEV_WM8978,
	AU_DEV_MA5I,
	AU_DEV_UDA1345TS
} AU_DEV_E;


INT  WAV_Open(WAPI_INOUT apidir ,PWAVEFORMATEX pFormat, AU_DEV_E eDev);
INT  WAV_IOControl(WAPI_INOUT apidir,UINT32 nCode,UINT32 nParam1,UINT32 nParam2,AU_DEV_E eDev);
INT  WAV_Close(WAPI_INOUT apidir,AU_DEV_E eDev);
#endif	/* _NUC900_AUDIO_H_ */
